﻿// ==UserScript==
// @name AngaraScrollUpBar
// @description Бар прокрутки для Ангара.нет 
// @author Gunslinger38
// @license MIT
// @version 1.0
// @include http://angara.net/*
// ==/UserScript==
(function (window, undefined) {
//проверочки  
    var w;
    if (typeof unsafeWindow != undefined) {
        w = unsafeWindow
    } else {
        w = window;
    }
    if (w.self != w.top) {
        return;
    }
    if (/http:\/\/angara.net/.test(w.location.href)) {
//скрыпт	
    var hovered = false;
	function main() {
		var divup = document.createElement('div');
		divup.id = 'divup';
		divup.setAttribute('style', 'top: 0px; left: 0px; width: 114px; height: 100%; opacity: 0; display: block; background-color: #9BF; position: fixed; ');
		divup.innerHTML = '<p font-weight: bold; font-color: blue; font-size: 12pt; margin-left: 10px; margin-top: 10px>▲ Наверх</P>';
		divup.style.zIndex = 10000;
		document.body.appendChild(divup);
		window.onscroll = onscroll;
		divup.onclick = divclick;
		divup.onmouseover=onmouseover; 
		divup.onmouseout=onmouseleave;
		onscroll();
		setopacity(0);	
	}
	function onscroll() {
		if (window.pageYOffset > 300) {
			setopacity(0.1);
			if (hovered) setopacity(0.5);
		}
		else setopacity(0);
		
		return;
	}

	function onmouseover() {	
		if (window.pageYOffset < 300) return;
			setopacity(0.5);
		hovered = true;
	}

	function onmouseleave() {
		if (window.pageYOffset < 300) setopacity(0)
		else setopacity(0.1)
		hovered = false;
		return;
	}

	function setopacity(max) {	
		//if (hovered) return;
		var divup = document.getElementById('divup').style.opacity = max;
	}

	function divclick() {
		if (window.pageYOffset > 300) {
		window.scrollTo(0,0);
		setopacity(0);
		}
		return;
	}

	main();

    }
})(window);
